package ace.tool.generate.code.impl.resolver.scheme.resolver.core;

import ace.cmp.util.CaseFormatUtils;
import ace.tool.generate.code.impl.resolver.scheme.model.bo.core.EntityClassInfo;
import ace.tool.generate.code.impl.resolver.scheme.model.bo.core.test.TestGraphqlAdminControllerTestClassInfo;
import ace.tool.generate.code.impl.resolver.scheme.model.dto.ClassFileInfo;
import ace.tool.generate.code.impl.resolver.scheme.model.dto.CommonInfo;
import ace.tool.generate.code.impl.resolver.scheme.model.dto.ProjectInfo;
import ace.tool.generate.code.impl.resolver.scheme.resolver.ClassFileInfoResolver;
import ace.tool.generate.code.impl.service.model.input.GenerateInput;
import lombok.Builder;
import lombok.RequiredArgsConstructor;

/**
 * @author caspar
 * @date 2023/11/17 10:34
 */
@Builder
@RequiredArgsConstructor
public class TestGraphqlAdminControllerTestClassInfoResolver {
  private final GenerateInput input;
  private final EntityClassInfo entityClassInfo;
  private final ProjectInfo coreProjectInfo;
  private final CommonInfo commonInfo;

  public TestGraphqlAdminControllerTestClassInfo resolve() {

    ClassFileInfo classFileInfo =
        ClassFileInfoResolver.builder()
            .className(this.entityClassInfo.getInfo().getClassName())
            .classNameSuffix(input.getTestGraphqlAdminControllerClassNameSuffix())
            .classPackagePrefix(input.getTestGraphqlAdminControllerClassPackagePrefix())
            .rootPackageFullName(commonInfo.getRootPackageFullName())
            .sourceCodeRootDir(coreProjectInfo.getTestSourceCodeRootDir())
            .build()
            .resolve();

    return TestGraphqlAdminControllerTestClassInfo.builder()
        .entityModelId(entityClassInfo.getEntityModelId())
        .info(classFileInfo)
        .securityPermissionPrefix(this.getSecurityPermissionPrefix())
        .build();
  }

  private String getSecurityPermissionPrefix() {
    return CaseFormatUtils.convertUpperCamelToLowerUnderscore(this.entityClassInfo.getInfo().getClassName())
        + "_admin";
  }
}
